<template>
  <div>
  </div>
</template>

<script>
import MenuUtils from '../../utils/MenuUtils'
import routerUtil from '../../utils/routerUtil'
let routers = []
export default {
  name: 'login',
  data () {
    return {
      user: {}
    }
  },
  methods: {
    loginIn (data) {
      window.sessionStorage.setItem('routers', JSON.stringify(data))
      MenuUtils(routers, data)
    },
    addDataToRouter (data) {
      this.loginIn(data)
      this.$router.addRoutes(routers)
    }
  },
  created () {
    this.$ajax.post('/branch/global/info')
      .then(res => {
        if (res.data.success) {
          document.title = res.data.data.brandInfo.brandName
          window.sessionStorage.setItem('brandName', res.data.data.brandInfo.brandName)
        }
      })
    this.$ajax.get('/admin/user/info')
      .then(res => {
        if (res.data.success) {
          // 加载配置路由
          this.user = res.data.data.userInfoVO
          this.$ajax.get('https://api.ttt.sh/ip/qqwry/' + this.user.lastLoginIp, {withCredentials: false, headers: {'Content-Type': 'text/html'}})
            .then(res => {
              this.$Notice.open({
                title: '上次登录信息',
                render: (h) => {
                  return h('ul', [
                    h('li', {
                      style: {
                        borderBottom: '1px solid #dddee1',
                        lineHeight: '30px'
                      }
                    }, '上次登录时间：' + new Date(this.user.lastLoginTime).toLocaleString()),
                    h('li', {
                      style: {
                        borderBottom: '1px solid #dddee1',
                        lineHeight: '30px'
                      }
                    }, '上次登录Ip：' + this.user.lastLoginIp),
                    h('li', {
                      style: {
                        lineHeight: '30px'
                      }
                    }, '上次登录地址：' + res.data.address)
                  ])
                },
                duration: 30
              })
            })
          let routerData = routerUtil(res.data.data)
          this.addDataToRouter(routerData)
          this.$router.push({name: 'index'})
        }
      })
  }
}
</script>

<style scoped>
  .user{
    width: 150px;
    margin: 0 auto;
  }
</style>
